<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>店仓管理-编辑店仓</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-table-master/dist/bootstrap-table.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header" >
			<a href="<%=basePath %>shop/listShop.do">店仓管理</a>
			<i class="icon-double-right"></i><a>编辑店仓</a>
			</div>
			<div class="btn rightBtn">
				<c:if test="${isEdit }">
					<input type="button" class="btn btn1" value="添加物品" onclick="toAddShopItem();"></input>
					<input type="button" class="btn btn1" value="保存" onclick="saveEditShop();"></input>
				</c:if>
				<input type="button" class="btn btn2" value="退出" onclick="location.href='<%=basePath %>shop/listShop.do'"></input>
			</div>
			<form id="update_shop_form" class="form">
			<div class="box formBox">
				<input type="hidden" name="shopid" value="${shop.shopid }">
				<p>
					<label>店仓代码</label>
					<input type="text" class="form-control" readonly value="${shop.storecode }"></input>
					<label class="must">店仓名称</label>
					<input type="text" class="form-control" name="annexname" value="${shop.annexname }"></input>
					<label class="must">联系电话</label>
					<input type="text" class="form-control" name="companytelephone" value="${shop.companytelephone }"></input>
					<label class="must">状态</label>
					<select name="annexpath" class="form-control select">
						<option value="可用" ${shop.annexpath=="可用"?"selected":"" }>可用</option>
						<option value="不可用" ${shop.annexpath=="不可用"?"selected":"" }>不可用</option>
					</select>
				</p>
				<p>
					<label class="must">地址</label>
					<input type="text" class="form-control doubleWidth" name="address" value="${shop.address }"></input>
					<label class="must">备注</label>
					<input type="text" class="form-control doubleWidth" name="description" value="${shop.description }"></input>
				</p>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th>物品代码</th>
							<th>物品名称</th>
							<th>物品条码</th>
							<th>当前库存</th>
							<th>零售价</th>
							<th>最低售价</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="hasAddItemTbody">
						<c:forEach items="${itemList}" var="item" varStatus="i">
							<tr>
								<td>${item.itemcode }</td>
								<td>${item.chinesename }</td>
								<td>${item.articlebarcode }</td>
								<td>${item.currentstock }</td>
								<td>${item.proposalprice }</td>
								<td>${item.latestprice }</td>
								<td><a onclick="deleteItem(this);">删除</a><input type="hidden" name="itemIds" value="${item.iteminformationid }"></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<div class="box updateBox">
				<p>
					<label>创建时间</label>
					<input type="text" class="form-control" readonly value="<fmt:formatDate value='${shop.createtime }' type='date'/>"></input>
					<label>最后处理时间</label>
					<input type="text" class="form-control" readonly value="<fmt:formatDate value='${shop.finalprocessingtime }' type='date'/>"></input>
				</p>
				<p>
					<label>创建人</label>
					<input type="text" class="form-control" readonly value="${shop.createpersonname }"></input>
					<label>最后处理人</label>
					<input type="text" class="form-control" readonly value="${shop.lastpersonname }"></input>
				</p>
			</div>
			</form>
		<jsp:include page="/jsp/basicData/shopManage/addShopItem.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
		</div>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>libs/bootstrap-table-master/dist/bootstrap-table.js"></script>
	<script src="<%=basePath %>libs/bootstrap-table-master/dist/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	function addToHasAddTable(item){
		var html="<tr>";
		html+="<td>"+item.itemcode+"</td>";
		html+="<td>"+item.chinesename+"</td>";
		html+="<td>"+item.articlebarcode+"</td>";
		html+="<td>"+item.currentstock+"</td>";
		html+="<td>"+item.proposalprice+"</td>";
		html+="<td>"+item.latestprice+"</td>";
		html+="<td><a onclick='deleteItem(this);'>删除</a>";
		html+="<input type='hidden' name='itemIds' value='"+item.iteminformationid+"' /></td>";
		html+="</tr>";
		$("#hasAddItemTbody").append(html);
	}
	
	function deleteItem(obj){
		$(obj).parent().parent().remove();
	}
	
	function saveEditShop(){
		
		if(!validateAddForm()) return ;//校验
		
		$.ajax({
			url:"<%=basePath %>shop/update.do",
			type:"post",
			async : false,
			dataType:"json",
			data : $("#update_shop_form").serialize(),
			success:function(data){
				if(data.result=="success"){
					Prompt.alert("提示","店仓保存成功！",Prompt.refresh);
				}else{
					Prompt.alert("提示","店仓保存失败！");
				}
			},
			error :function(){
				Prompt.alert("提示","修改店仓失败！");
			}
		});
	}
	
	function chooseAnnex(){
		var annex=$("#supplyAgreementAnnex").val();
		var arr=annex.split('\\');
	    var fileName=arr[arr.length-1];
		if(annex==""){
			$("#supplyAgreementAnnexName").html("选择文件")
		}else{
			$("#supplyAgreementAnnexName").html(fileName)
		}
	}

	//店仓管理校验
	function validateAddForm(){
		
		if(!validateString("店仓名称","#update_shop_form [name='annexname']",30,false)){
			return false;
		} 
		
		if(!validateRegex("联系方式","#update_shop_form [name='companytelephone']",/^1[0-9]{10}$/,false)){
			return false;
		}
		
		 if(!validateSelect("状态","#update_shop_form [name='annexpath']",120,false)){
			return false;
		}
		
		if(!validateString("地址","#update_shop_form [name='address']",120,false)){
			return false;
		}
		
		if(!validateString("备注","#update_shop_form [name='description']",190,false)){
			return false;
		} 
		return true;
	}
	
	</script>
</body>
</html>